package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.AnswerComment;
import cn.wolfcode.trip.base.domain.QuestionComment;
import cn.wolfcode.trip.base.mapper.AnswerCommentMapper;
import cn.wolfcode.trip.base.mapper.QuestionCommentMapper;
import cn.wolfcode.trip.base.service.IAnswerCommentService;
import cn.wolfcode.trip.base.service.IQuestionCommentService;
import cn.wolfcode.trip.base.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AnswerCommentServiceImpl implements IAnswerCommentService {

    @Autowired
    private AnswerCommentMapper answerCommentMapper;

    // 保存问题评论
    @Override
    public void save(AnswerComment answerComment) {
        answerComment.setUser(UserContext.getCurrentUser());
        answerComment.setCreateTime(new Date());
        answerCommentMapper.insert(answerComment);
    }

    // 获取所有问题评论
    @Override
    public List<AnswerComment> listAllById(Long id) {
        return answerCommentMapper.selectAllById(id);
    }

    // 获取问题评论数
    @Override
    public int getCommentCountByAnswerId(Long id) {
        return answerCommentMapper.queryForCountById(id);
    }
}
